package com.scors.logos.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;


@Entity
@Table(name = "user")
public class User implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    private Long id;

    @Column(name = "name", unique = false, nullable = false, length = 25)
    private String name;

    @Column(name = "fullname", unique = false, nullable = false, length = 25)
    private String fullname;

    @Column(name = "login", unique = true, nullable = false)
    private String login;

    @Column(name = "password", unique = false, nullable = false)
    private String password;

    @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private Set<User> friends = new HashSet<User>();

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private Set<Media> mediaList = new HashSet<Media>();

    public Long getId() {
	return id;
    }

    public String getName() {
	return name;
    }

    public void setName(String name) {
	this.name = name;
    }

    public String getFullname() {
	return fullname;
    }

    public void setFullname(String fullname) {
	this.fullname = fullname;
    }

    public String getLogin() {
	return login;
    }

    public void setLogin(String login) {
	this.login = login;
    }

    public String getPassword() {
	return password;
    }

    public void setPassword(String password) {
	this.password = password;
    }

    public Set<User> getFriends() {
	return friends;
    }

    public void setFriends(Set<User> friends) {
	this.friends = friends;
    }

    public Set<Media> getMediaList() {
	return mediaList;
    }

    public void setMediaList(Set<Media> mediaList) {
	this.mediaList = mediaList;
    }

    public void setId(Long id) {
	this.id = id;
    }

    public void addFriend(User user) {
	this.getFriends().add(user);
	user.getFriends().add(this);
    }

    public void deleteFriend(User user) {
	this.getFriends().remove(user);
	user.getFriends().remove(this);

    }

}
